package com.tjec.project.msg.mobset.sms;

import com.tjec.project.msg.mobset.bean.DataObjectBean;
import com.tjec.project.msg.mobset.bean.msmResultBean;
import com.tjec.project.msg.mobset.factory.DataObjectFactory;
import com.tjec.project.msg.tempuri.MobsetApiSoap;
import com.tjec.project.msg.util.MD5;

import java.net.URL;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.rpc.holders.LongHolder;
import javax.xml.rpc.holders.StringHolder;


public class sms_GetSign {
	private static long corpID;      					//��ҵID
	private static String loginName;					//��¼�ʺ�
	private static String password;						//���룬MD5(CorpID+�ʺ�����+TimeStamp)
	private static	URL url;
	private static String timeStamp = "1105203910";		//ʱ�����MMDDHHMMSS������ʱ����),��0514094912
	private static StringHolder errMsg;					//������Ϣ�����ڷ��غ������ý������������
	private static LongHolder errCode;					//���ػ�ȡǩ����״ֵ̬
	private static StringHolder sign;					//����ǩ�������ڷ��ش��ʺ������õĶ���ǩ��

	public static msmResultBean getSign(){
		Date now = new Date(); 
		SimpleDateFormat dateFormat = new SimpleDateFormat("MMddHHmmss");//���Է�����޸����ڸ�ʽ
		timeStamp = dateFormat.format(now); 
		System.out.println(timeStamp); 
		//���ʵ��������
		//MobsetApiSoap mobset = DataObjectFactory.getMobsetApi();
		errMsg = new StringHolder();
		errCode = new LongHolder();
		sign = new StringHolder();
		msmResultBean msmBean = new msmResultBean();
		
		//��ȡ�ʺ���Ϣ
		DataObjectBean bean = DataObjectFactory.getInstance();
		corpID = new Long(bean.getCordId());
		loginName = bean.getUserName();
		password = bean.getPasswd();
		try
		{
		url=new URL(bean.getServerIP());
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        MobsetApiSoap mobset = DataObjectFactory.getMobsetApi(url);
		//MD5�������
		MD5 md5 = new MD5();
		password = md5.getMD5ofStr(corpID+password+timeStamp);
		
		try {
				mobset.sms_GetSign(corpID, loginName, password, timeStamp, errCode, errMsg, sign);
				msmBean.setErrMsg(errMsg);
				msmBean.setErrCode(errCode);
				msmBean.setSign(sign);
				
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return msmBean;
	}
}
